<?php

session_start();

error_reporting(E_ALL); //TODO change this prior to release

require_once 'config.php';

function umAutoload($classname){
	if(is_file(config::getDocRoot().'classes/'.$classname.'.class.php')){
		include_once config::getDocRoot().'classes/'.$classname.'.class.php';
	}
}

spl_autoload_register('umAutoload');

try{
	if(empty($_GET['action'])) $_GET['action'] = 'main';
	
	$action = action::generate($_GET['action']);
	
	$action->display();
}catch(Exception $e){
	switch($e->getCode()){
		case 404:
			$action = action::generate(404);
			break;
		case 403:
			$action = action::generate(403);
			break;
		case 600:
			$action = action::generate(600);
			break;
		case 500:
		default:
			$action = action::generate(500);
	}
	
	$action->display($e);
	
	
	echo '<div class="container"><hr /><h1>DETAILED ERROR:</h1>';
	echo '<pre>'.$e->getTraceAsString().'</pre>';
	echo '<pre>'.$e->getMessage().'</pre></div>';
	
}
